#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from dragon.selector import Selector
from dragon.page import DraPage

class CalendarSe:
        #日历
    optionalDate=Selector('div[tabindex="-1"].van-calendar__day','可选日期')
    latestMonth=Selector('div:nth-last-child(1) > div.van-calendar__days','最近一个月')
    confirmButton=Selector('div.van-calendar__footer.van-safe-area-bottom','确定按钮')
    cancelButton=Selector('i[role="button"]','取消按钮')
    selectedDate=Selector('div.van-calendar__selected-day','已选中的日期')
    monthBlock=Selector('.van-calendar__month','月份块')
    month=Selector('.van-calendar__month-title','月份')
    selectedMonth=Selector('.van-calendar__month:has(div.van-calendar__selected-day)>>.van-calendar__month-title','选中的月份')

class Calendar:
    def __init__(self, draPage: DraPage):
        self.draPage = draPage
        self.optionalDate=draPage.locator(CalendarSe.optionalDate)
        self.latestMonth=draPage.locator(CalendarSe.latestMonth)
        self.confirmButton=draPage.locator(CalendarSe.confirmButton)
        self.cancelButton=draPage.locator(CalendarSe.cancelButton)
        self.selectedDate=draPage.locator(CalendarSe.selectedDate)
        self.monthBlock=draPage.locator(CalendarSe.monthBlock)
        self.month=draPage.locator(CalendarSe.month)
        self.selectedMonth=draPage.locator(CalendarSe.selectedMonth)

    def pick_date_by_index(self,index:int):
        self.optionalDate.nth(index).click()
        self.confirmButton.click()



